package com.th.supcom.pds.phamapply.client.widget.inpharmacyreturn;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;

/**
 * 住院药房退药主面板.
 * 
 * @author yzhang
 */

public class InPharmacyReturnMainPanel extends ContentPanel
{
    /** 退药按钮 */
    private InPharmacyReturnButtons m_inPharmacyReturnButtons;
    /** 退药文本域 */
    private InPharmacyReturnFields m_inPharmacyReturnFields;
    /** 退药 action */
    private InPharmacyReturnAction m_inPharmacyReturnAction;
    /** 退药明细表 */
    private InPharmacyReturnGridPanel m_inPharmacyReturnGridPanel;
    /** 退药信息主表 */
    private InPharmacyReturnMasterGridPanel m_inPharmacyReturnMasterGridPanel;

    public InPharmacyReturnMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        setHeaderVisible (false);
        setBorders (false);
        setLayout (new BorderLayout ());
        // 初始化对象
        m_inPharmacyReturnButtons = new InPharmacyReturnButtons ();
        m_inPharmacyReturnFields = new InPharmacyReturnFields ();
        InPharmacyReturnQueryPanel inPharmacyReturnQueryPanel = new InPharmacyReturnQueryPanel (m_inPharmacyReturnFields,
                                                                                                m_inPharmacyReturnButtons);
        m_inPharmacyReturnGridPanel = new InPharmacyReturnGridPanel ();
        m_inPharmacyReturnMasterGridPanel = new InPharmacyReturnMasterGridPanel ();
        // 设置布局和大小
        BorderLayoutData northData = new BorderLayoutData (LayoutRegion.NORTH, 60);
        northData.setMargins (new Margins (4, 4, 4, 4));
        BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER);
        centerData.setMargins (new Margins (4, 4, 4, 4));
        BorderLayoutData westData = new BorderLayoutData (LayoutRegion.WEST, 220);
        westData.setMargins (new Margins (4, 0, 4, 4));
        add (inPharmacyReturnQueryPanel, northData);
        add (m_inPharmacyReturnGridPanel, centerData);
        add (m_inPharmacyReturnMasterGridPanel, westData);
        m_inPharmacyReturnFields.getPrescNoField ().focus ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_inPharmacyReturnAction = new InPharmacyReturnAction ();
        m_inPharmacyReturnAction.setInPharmacyReturnFields (m_inPharmacyReturnFields);
        m_inPharmacyReturnAction.setInPharmacyReturnGridPanel (m_inPharmacyReturnGridPanel);
        m_inPharmacyReturnAction.setInPharmacyReturnMasterGridPanel (m_inPharmacyReturnMasterGridPanel);
        m_inPharmacyReturnAction.setMainPanel (this);
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        /** 门诊退药Listener */
        InPharmacyReturnListener drugReturnListener = new InPharmacyReturnListener ();
        drugReturnListener.setInPharmacyReturnAction (m_inPharmacyReturnAction);
        drugReturnListener.setInPharmacyReturnButtons (m_inPharmacyReturnButtons);
        drugReturnListener.setInPharmacyReturnFields (m_inPharmacyReturnFields);
        drugReturnListener.setInPharmacyReturnMasterGridPanel (m_inPharmacyReturnMasterGridPanel);
        drugReturnListener.setKeyNavComponent (this);
        drugReturnListener.initListeners ();
    }

    /** 提交路径. */
    public static final String SCC_BRANCH = "$URL$";
    /** 提交日期. */
    public static final String SCC_LAST_MODIFICATION_DATE = "$Date$";

    /** 最终修改人员. */
    public static final String SCC_LAST_MODIFIER_NAME = "$Author$";

    /** 最终版本号. */
    public static final String SCC_REVISION = "$Revision$";
}